-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Updated "while let" example. #30059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated "while let" example. #30059
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
The text seemed confusing as-is, since it appeared to have no halting condition (are we iterating over " |
@bors: r+ rollup I agree, this is nicer, thanks. |
📌 Commit b1c5c26 has been approved by |
This explanation implies that |
Can you recommend an improvement, or does this mean you think it should stay as-is? |
Proposal: I should restore the original prose and leave the example code as shown. |
@brson: ahhh, shucks, reading this, my brain said "while uses an iterator, sure", but while != while let. @androm3da how about changing it so that the whole example is visible, and remove the temporary? |
@bors: r- for now |
@steveklabnik "The temporary" refers to " |
It's all good! I myself made a mistake: when thinking about it, i was thinking this:
but that doesn't work. This should be fine:
|
# let option: Option<i32> = None; | ||
while let Some(x) = option { | ||
let v: vec![1, 3, 5, 7, 11, ]; | ||
let mut iter: v.iter(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be =, not : on these two lines.
But, why not show off something else than iterators since that's a good while let speciality? For example looping over the result of v.pop()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut v = vec![1, 3, 5, 7, 11];
while let Some(x) = v.pop() {
println!("{}", x);
}
(A comment on the PR is needed to notify people involved, a pushed commit does not notify, so that's the reason for the two day delay). |
No description provided.